package savefile;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*4)、使用TCP协议实现客户端上传文件到服务器，服务器接收到文件将其保存到指定目录中，
要求服务器可以处理多个客户端上传请求？*/
public class ServerFile {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ServerSocket serverSocket = null;
        Socket socket = null;
        List<File> fileList = new ArrayList<>();
        ExecutorService ThreadPool = Executors.newCachedThreadPool();
        ObjectInputStream ois = null;

            try {
                serverSocket = new ServerSocket(6248);
                while (true){
                    socket = serverSocket.accept();
                    ThreadPool.execute(new FileThred(socket));//一直监听，直到有客户端连接上来
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

    }
}
